package com.cn.project.service.impl;

import com.cn.common.pojo.ProjectModel;
import com.cn.common.pojo.ResultModel;
import com.cn.project.mapper.ProjectDao;
import com.cn.project.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    ProjectDao projectDao;

    @Override
    public ResultModel PForP() {
        return ResultModel.Data(projectDao.PForP());
    }

    @Override
    public List<ProjectModel> PByType(int type) {
        return projectDao.PByType(type);
    }

    @Override
    public ResultModel PForId(int id) {
        List<ProjectModel> projectModels  = projectDao.PForId(id);
        return ResultModel.getResultModel("",0,1,projectModels);
    }

    @Override
    public ResultModel project() {
        return ResultModel.getResultModel("success",0,1,projectDao.project());
    }

    @Override
    public ResultModel delete(int id) {
        int delete = projectDao.delete(id);
        return ResultModel.getResultModelByCount(delete);
    }

    @Override
    public ResultModel update(ProjectModel projectModel) {
        int update = projectDao.update(projectModel);
        return ResultModel.getResultModelByCount(update);
    }

    @Override
    public ResultModel insert(ProjectModel projectModel) {
        int insert = projectDao.insert(projectModel);
        return ResultModel.getResultModelByCount(insert);
    }

    @Override
    public ResultModel enable(int id) {
        int enable = projectDao.enable(id);
        return ResultModel.getResultModelByCount(enable);
    }

    @Override
    public ResultModel findById(int id) {

        return ResultModel.getResultModelByAll(projectDao.findById(id),1);
    }

    @Override
    public ResultModel limit(ProjectModel projectModel) {
        int count = projectDao.count(projectModel);
        return ResultModel.getResultModel("",0,count,projectDao.limit(projectModel));
    }
}
